package com.tz.platform.tag.common;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import com.tz.platform.utils.StringUtil;

@SuppressWarnings("serial")
public abstract class InfoTag extends TagSupport {

	private String id;         //唯一的标识
	private String name;       //元素的名称
	private String type;       //类型
	private String title;
	private String value;
	private String maxLength;
	private String minLength;
	private String cssClass;
	private String cssStyle;
	private String width;
	private String height;
	private String disabled;
	private String readOlny;
	private String pattern;
	private String placeholder;
	private String required;
	private String size;
	private String src;
	
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getValue() {
		return value;
	}
	public void setValue(String value) {
		this.value = value;
	}
	public String getMaxLength() {
		return maxLength;
	}
	public void setMaxLength(String maxLength) {
		this.maxLength = maxLength;
	}
	public String getMinLength() {
		return minLength;
	}
	public void setMinLength(String minLength) {
		this.minLength = minLength;
	}
	public String getCssClass() {
		return cssClass;
	}
	public void setCssClass(String cssClass) {
		this.cssClass = cssClass;
	}
	public String getCssStyle() {
		return cssStyle;
	}
	public void setCssStyle(String cssStyle) {
		this.cssStyle = cssStyle;
	}
	public String getWidth() {
		return width;
	}
	public void setWidth(String width) {
		this.width = width;
	}
	public String getHeight() {
		return height;
	}
	public void setHeight(String height) {
		this.height = height;
	}
	public String getDisabled() {
		return disabled;
	}
	public void setDisabled(String disabled) {
		this.disabled = disabled;
	}
	public String getReadOlny() {
		return readOlny;
	}
	public void setReadOlny(String readOlny) {
		this.readOlny = readOlny;
	}
	public String getPattern() {
		return pattern;
	}
	public void setPattern(String pattern) {
		this.pattern = pattern;
	}
	public String getPlaceholder() {
		return placeholder;
	}
	public void setPlaceholder(String placeholder) {
		this.placeholder = placeholder;
	}
	public String getRequired() {
		return required;
	}
	public void setRequired(String required) {
		this.required = required;
	}
	public String getSize() {
		return size;
	}
	public void setSize(String size) {
		this.size = size;
	}
	public String getSrc() {
		return src;
	}
	public void setSrc(String src) {
		this.src = src;
	}
	
	@Override
	public int doStartTag() throws JspException {
		StringBuffer strOut = new StringBuffer();
		if ( !StringUtil.msIsEmpty(getId()) ) {
			setId(getName());
		}
		strOut.append("<input id=\"" + getId() + "\" name=\"" + getName() + "\"");
		if ( !StringUtil.msIsEmpty(getType()) ) {
			strOut.append(" type=\"" + getType());
		}else{
			strOut.append(" type=\"text\"");
		}
		if ( !StringUtil.msIsEmpty(getCssClass()) ) {
			strOut.append(" class=\"" + getCssClass());
		}
		strOut.append("\"");
		if ( !StringUtil.msIsEmpty(getCssStyle()) ) {
			strOut.append(" style=\"" + getCssStyle() + "\"");
		}
		if ( !StringUtil.msIsEmpty(getPlaceholder())) {
			strOut.append(" placeholder=\"" + getPlaceholder() + "\"");
		}
		if ( !StringUtil.msIsEmpty(getMaxLength())) {
			strOut.append(" maxlength=\"" + getMaxLength() + "\"");
		}
		if ( !StringUtil.msIsEmpty(getDisabled())) {
			strOut.append(" disabled=\"disabled\"");
		}
		if ( !StringUtil.msIsEmpty(getReadOlny())) {
			strOut.append(" readonly=\"readonly\"");
		}
		//增加特殊的标签字段
		strOut.append(getTDContent());
		strOut.append("/>");
		try {
			pageContext.getOut().write(strOut.toString());
		} catch (IOException e) {
			e.printStackTrace();
		}
		return EVAL_BODY_INCLUDE;
	}
	
	public abstract String getTDContent() throws JspException;
	
}
